<?php
define('IN_DICE', true);
define( 'DIR_ROOT', dirname( __FILE__ ) . '/' );

set_time_limit(30);   //设置脚本执行时间
date_default_timezone_set('Asia/Shanghai');//设置时区

require DIR_ROOT . 'cfg/cfg.inc.php'; //加载配置文件
include DIR_MDL . 'base.php'; //加载base

all::setcfg( $cfg ); //设置配置文件
all::$aOut = $aOut; //全局输出变量

include DIR_LIB . 'func.php'; //公共库文件
include DIR_LIB . 'class.page.php'; //分页类

func::header();
func::dp3p();

all::loadlang( all::$cfg['lang'] ); //设置系统默认语言
include DIR_MDL . 'model.php'; //加载model
include DIR_CTL . 'control.php'; //加载控制器基类

$aBrowser = func::getbrowser();
if( empty( $aBrowser ) && isset( $argv ) && count( $argv ) > 1 ) { //从命令行下调用
  $m = $argv[1];
  $a = $argv[2];
} else {
  $m = empty($_REQUEST['m']) ? 'index' : func::input ( 'm' );
  $a = empty($_REQUEST['a']) ? 'index' : func::input ( 'a' );
  if (PRODUCT_ENV === true && $m == 'script') { //生产环境下不允许用浏览器调用定时任务
    //die('Action not found!');
  }
}

if( !S('debug') && $m != 'script' ) {
  include DIR_DAT . 'stop.php'; //加载停机控制文件
}

if( PRODUCT_ENV === true && defined( 'DICE_TEST' ) ) {
  func::showerr( 'Test over!' );
}

//允许操作的model
$aM = array('index','game','gw','script','test','apppay','pfpay');
if( in_array( $m, $aM ) ) {
  if( file_exists( DIR_CTL . "$m.php" ) ) {
    include DIR_CTL . "$m.php";
  }
  $classname = $m;
  $control = new $classname();
  $method = $a;
  if(method_exists($control, $method) && $a{0} != '_') {
    $data = $control->$method();
    exit;
  } else {
    exit('Action not found!');
  }
}

exit('Module not found!');